
#ifndef   ___SYS_CLOCK__H_
#define   ___SYS_CLOCK__H_

extern volatile int Time_1000ms;

//int Delay = 0, TimerStart = 0, TimeOut = 0, TimeOutStart = 0;

/* Timer 0 */
#define   SYS_CLOCK__TIMER_0_INTERVAL		10	/* ms */
#define   SYS_CLOCK_TIMER_0_MAX				0x0FFFFFFF
#define   T0_CLK									SYS_CLOCK__TIMER_0_INTERVAL


/* Timer 1 */

#define   SYS_CLOCK__TIMER_1_INTERVAL		1                  
#define   SYS_CLOCK_1_TIMER_MAX				0x0FFFFFFF	// max = ~72 Hours
//#define   SYS_CLOCK_1_TIMER_MAX				0x1FF

#define   TIME_PASS_1(TIMER_START) 	((SysTimer_1 - TIMER_START + SYS_CLOCK_1_TIMER_MAX)%SYS_CLOCK_1_TIMER_MAX)


extern volatile int SysTimer;
extern volatile int SysTimer_1;

extern unsigned int Sys_Time;

#define   SYS_CLOCK_10ms			(Sys_Time && !(Sys_Time%10))
#define   SYS_CLOCK_100ms			(Sys_Time && !(Sys_Time%100))
#define   SYS_CLOCK_500ms			(Sys_Time && !(Sys_Time%500))
#define   SYS_CLOCK_1000ms			(Sys_Time && !(Sys_Time%1000))
#define   SYS_CLOCK_10sec			(Sys_Time && !(Sys_Time%10000))	

//extern volatile int iTime_500, iTime_1000, iTime_5000, iTime_10000, i_Time;
extern int eTime_1, eTime_500, eTime_1000, eTime_5000, eTime_10000;

//extern volatile int  T_1000;

void SysTimer_Init( unsigned int Interval );	/* in msec */
void eSynchro ( void );
 
void Timer_1_Init( unsigned int Interval );

void SysClock ( void );

#endif


/* C:\WinAVR-20070525\bin;C:\WinAVR-20070525\utils\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;%HTC_PIC%\BIN;%HTC_PIC18%\BIN;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\WinARM\bin;C:\WinARM\utils\insight\bin;C:\emacs-21.3\bin;D:\CYGWIN\bin;D:\CYGWIN\usr\local\bin\;C:\Program Files\Flash Magic;C:\Program Files\HI-TECH Software\PICC\std\9.60\bin;c:\Program Files\Microchip\PICkit 2 v2\CommandLine;C:\Program Files\Altium Designer 6\System;c:\gnuarm\bin;C:\OrCAD\OrCAD_15.7\tools\PSpice;C:\OrCAD\OrCAD_15.7\tools\PSpice\Library;C:\OrCAD\OrCAD_15.7\tools\Capture;C:\OrCAD\OrCAD_15.7\tools\bin;C:\OrCAD\OrCAD_15.7\tools\fet\bin;C:\OrCAD\OrCAD_10.5\tools\PSpice\Library;C:\OrCAD\OrCAD_10.5\tools\bin;C:\OrCAD\OrCAD_10.5\tools\fet\bin;C:\OrCAD\OrCAD_10.5\tools\Capture;C:\Program Files\7-Zip;C:\Program Files\Mono-1.2.6\bin\;D:\Programs\PICkit2Setupv2.40a\CommandLine;C:\Program Files\TortoiseSVN\bin */

/* %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\OrCAD\OrCAD_15.7\tools\pcb\bin;C:\OrCAD\OrCAD_15.7\tools\specctra\bin;C:\OrCAD\OrCAD_15.7\tools\fet\bin;C:\OrCAD\OrCAD_15.7\tools\PSpice;C:\OrCAD\OrCAD_15.7\tools\PSpice\Library;C:\OrCAD\OrCAD_15.7\tools\Capture;C:\OrCAD\OrCAD_15.7\tools\bin;D:\cygwin\bin;C:\emacs-21.3\bin;%HTC_PIC18%\BIN;C:\WinARM\bin;C:\PK2CMD;C:\Program Files\TortoiseSVN\bin;%HTC_PIC%\BIN */






/* #define   TIME_PASS(TIMER_START) 	((SysTimer - TIMER_START + SYS_CLOCK_0_TIMER_MAX)%SYS_CLOCK_0_TIMER_MAX) */

/* #define   TIME_WHICH_PASS() 			((SysTimer - TimerStart + SYS_CLOCK_0_TIMER_MAX)%SYS_CLOCK_0_TIMER_MAX) */

/* #define   TIMER_CHECK()					if(Delay){if(TIME_WHICH_PASS()>=Delay){Delay=0;}else{return Result;}} */
/* //#define   TIMER_CHECK()					if(Delay)if(TIME_WHICH_PASS()>=Delay)Delay=0;else return */
                                 
/* #define   TIMEOUT_WHICH_PASS()		((SysTimer - TimeOutStart + SYS_CLOCK_0_TIMER_MAX)%SYS_CLOCK_0_TIMER_MAX) */
/* #define   TIMEOUT_CHECK() 				if(TimeOut){if(TIMEOUT_WHICH_PASS() >= TimeOut){TimeOut=0;State=TIMEOUT;}} */

/* #define   TIMER_START(DELAY)			TimerStart=SysTimer;Delay=(int)DELAY  */

/* #define   TIMEOUT_SET(TIMEOUT)		TimeOutStart=SysTimer;TimeOut=(TIMEOUT>>3)  */
